
	********************************************************************
	** WAVE 4 POST-HARVEST DATA
	********************************************************************

	** Post harvest has roster, labor, and health data

		use "$dir/rawdata/LSMS Nigeria/2018/sect1_harvestw4.dta", clear // ROSTER
		merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2018/sect3a_harvestw4.dta", gen(merge_sec3a) assert(master matched) // LABOR
		merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2018/sect4a_harvestw4.dta", gen(merge_sec4) assert(master matched) // HEALTH
		
	***********
	***********

	** INFORMATION FROM HOUSEHOLD ROSTER

		** Still in HH
		gen w4h_inhh=s1q4a!=2

		** Household size
		gen temp=1 if w4h_inhh==1
		bys hhid: egen w4h_hh_size=total(temp)
		drop temp

		** Number of children 12 or younger
		gen temp=1 if s1q4<=12 & w4h_inhh==1
		bys hhid: egen w4h_hh_under12=total(temp)
		drop temp

		** Number of youth 18 or younger
		gen temp=1 if s1q4<=18 & w4h_inhh==1
		bys hhid: egen w4h_hh_under18=total(temp)
		drop temp

		** Number of adults 60 or older
		gen temp=1 if s1q4>=60 & !missing(s1q4) & s1q4!=999 & w4h_inhh==1
		bys hhid: egen w4h_hh_over60=total(temp)
		drop temp

		** Adults 12 to 60
		gen temp=1 if s1q4>12 & s1q4<60 & !missing(s1q4) & s1q4!=999 & w4h_inhh==1
		bys hhid: egen w4h_hh_12to60=total(temp)
		drop temp

		** Marital status
		gen w4h_married=(s1q7==1 | s1q7==2) if !missing(s1q7)
		gen w4h_married_monog=(s1q7==1) if !missing(s1q7)
		gen w4h_married_polyg=(s1q7==2) if !missing(s1q7)

		** Female
		gen w4h_female=(s1q2==2) if !missing(s1q2)

		** Age
		gen w4h_age=s1q4
		replace w4h_age=. if w4h_age==999

		** Age of spouse
		sum indiv 
		forvalues x=1/`r(max)' {
			gen age_person`x'_temp=s1q4 if indiv==`x' & !missing(s1q4)
			bys hhid: egen age_person`x'=max(age_person`x'_temp)
			drop age_person`x'_temp
		}

		** Average age of others in the household
		sum indiv 
		forvalues x=1/`r(max)' {
			replace age_person`x'=. if indiv==`x'
		}
		egen w4h_hh_avgage=rowmean(age_person*)

		** Spouse age
		sum indiv
		forvalues x=1/`r(max)' {
			replace age_person`x'=. if s1q12_1!=`x' // FIXME: Could do this more carefully since several indices for spouses allowed
		}
		egen w4h_spouse_age=rowmean(age_person*)

		** Age gap
		gen w4h_spouse_agegap=w4h_age-w4h_spouse_age

		** Birthday
		gen w4h_birthday=mdy(s1q6_month,s1q6_day,s1q6_year)
		format w4h_birthday %td

		** Birth year
		gen w4h_birthyear=s1q6_year
		recode w4h_birthyear 9999=. 9998=.
		replace w4h_birthyear=2018-w4h_age if missing(w4h_birthyear)
	
	***********
	***********
	
	** Geographic information
	
		gen w4h_geo_urban=(sector==1) if !missing(sector)
		gen w4h_geo_state=state
		gen w4h_geo_lga=lga
		replace w4h_geo_lga=s1q31b if !missing(s1q31b) // LGA code for where the HH member moved
		label var w4h_geo_urban "Urban residence"
		label var w4h_geo_state "State of residence"
		label var w4h_geo_lga "LGA of residence" 
	
	***********
	***********
	
	** DISABILITIES

	** Difficulty seeing
		tab1 s4aq23, nol
		tab1 s4aq23
		gen w4h_diff_seei=1 if inlist(s4aq23, 2, 3, 4) 
		replace w4h_diff_seei=0 if inlist(s4aq23, 1)
		replace w4h_diff_seei=. if inlist(s4aq23, .)
		tab1 w4h_diff_seei

	** Difficulty hearing
		tab1 s4aq25, nol
		tab1 s4aq25
		gen w4h_diff_hear=1 if inlist(s4aq25, 2, 3, 4) 
		replace w4h_diff_hear=0 if inlist(s4aq25, 1)
		replace w4h_diff_hear=. if inlist(s4aq25, .)
		tab1 w4h_diff_hear

	** Difficulty walking or climbing stairs	
		tab1 s4aq27, nol
		tab1 s4aq27
		gen w4h_diff_walk_clim=1 if inlist(s4aq27, 2, 3, 4) 
		replace w4h_diff_walk_clim=0 if inlist(s4aq27, 1)
		replace w4h_diff_walk_clim=. if inlist(s4aq27, .)
		tab1 w4h_diff_walk_clim

	** Difficulty remembering or concentrating
		tab1 s4aq29, nol
		tab1 s4aq29
		gen w4h_diff_reme=1 if inlist(s4aq29, 2, 3, 4) 
		replace w4h_diff_reme=0 if inlist(s4aq29,1)
		replace w4h_diff_reme=. if inlist(s4aq29, .)
		tab1 w4h_diff_reme

	** Difficulty with self-care
		tab1 s4aq31, nol
		tab1 s4aq31
		gen w4h_diff_self_care=1 if inlist(s4aq31, 2, 3, 4)
		replace w4h_diff_self_care=0 if inlist(s4aq31, 1)
		replace w4h_diff_self_care=. if inlist(s4aq31, .)
		tab1 w4h_diff_self_care

	** Difficulty communicating
		tab1 s4aq33, nol
		tab1 s4aq33
		gen w4h_diff_comm=1 if inlist(s4aq33, 2, 3, 4) 
		replace w4h_diff_comm=0 if inlist(s4aq33, 1)
		replace w4h_diff_comm=. if inlist(s4aq33, .)
		tab1 w4h_diff_comm

	***********
	***********

	** LABOR

		** Worked for a non-HH member
		gen w4h_work_outsideHH=s3q4==1 if !missing(s3q4)
		gen w4h_work_outsideHH_hrs=s3q4b
		replace w4h_work_outsideHH_hrs=0 if w4h_work_outsideHH==0

		** Worked in agriculture for a HH member
		gen w4h_work_agHH=s3q5==1 if !missing(s3q5)
		gen w4h_work_agHH_hrs=s3q5b
		replace w4h_work_agHH_hrs=0 if w4h_work_agHH==0

		** Worked in HH business
		gen w4h_work_bizHH=s3q6==1 if !missing(s3q6)
		gen w4h_work_bizHH_hrs=s3q6b
		replace w4h_work_bizHH_hrs=0 if w4h_work_bizHH==0

		** Any work in last 7 days (agriculture, for non-HH member, own account/business)
		gen w4h_worked_last7days=0
		replace w4h_worked_last7days=1 if s3q4==1
		replace w4h_worked_last7days=1 if s3q5==1 
		replace w4h_worked_last7days=1 if s3q6==1
		replace w4h_worked_last7days=. if missing(s3q4) & missing(s3q5) & missing(s3q6)

		** Hours worked in last 7 days
		egen w4h_work_hrs=rowtotal(w4h_work_outsideHH_hrs w4h_work_agHH_hrs w4h_work_bizHH_hrs)
		replace w4h_work_hrs=. if missing(w4h_work_outsideHH_hrs) & missing(w4h_work_agHH_hrs) & missing(w4h_work_bizHH_hrs)

		** Works in agriculture
		gen w4h_work_agri=(w4h_work_agHH==1 | s3q14==1) if (!missing(w4h_work_agHH) | !missing(s3q14))
		
	***********
	***********

	** HEALTH
		
		** Any illness or injury during the last 4 weeks
			gen w4h_ill_inj=(s4aq3==1) if !missing(s4aq3)

		** Had to stop usual activity in the past 4 weeks
			gen w4h_ill_inj_stopactivity=(s4aq4==1) if !missing(s4aq4)
			replace w4h_ill_inj_stopactivity=0 if w4h_ill_inj==0
			
		
	** HH CONSUMPTION
	
		merge m:1 hhid using "$dir/rawdata/LSMS Nigeria/2018/totcons_final.dta", assert(master matched) nogen
		gen w4h_urban_fromcons=sector==1 if !missing(sector)
		ren totcons_pc w4h_conspc
		ren hhsize w4h_hhsize_fromcons
			
			
	**********
	**********
	
		keep hhid indiv w4h*
		order hhid indiv w4h*
		save "$dir/data/NGA_w4h_individual.dta", replace
